#ifndef FD_BUS_SERVLET_H
#define FD_BUS_SERVLET_H
#include "IServlet.h"

class FDBusClientServlet : public IServlet {
public:
    virtual void on(SERVLET_STATUS type,std::function<int(ISession *session,void*,int)> handler);
    virtual void request(const void *data,int len);
    virtual void start();
    virtual void wait();
    virtual void stop();
    virtual void onLoad(INode *node);
    virtual void onMessage(ISession *session,void* data,int size);
    virtual void onState(SERVLET_STATUS status,int code);
private:
    std::string name;
    std::string url;
    void *_client = 0;
    std::map<int,std::function<int(ISession *,void*,int)> >  msgidHandlers;
};

class FDBusServerServlet : public IServlet {
public:
    virtual void on(SERVLET_STATUS type,std::function<int(ISession *session,void*,int)> handler);
    virtual void request(const void *data,int len);
    virtual void start();
    virtual void wait();
    virtual void stop();
    virtual void onLoad(INode *node);
    virtual void onMessage(ISession *session,void* data,int size);
     virtual void onState(SERVLET_STATUS status,int code);
private:
    std::string name;
    std::string url;
    std::map<int,std::function<int(ISession *,void*,int)> >  msgidHandlers;
};

class FDBusStartup : public IPlugin {
public:
    virtual void onLoad(INode *node);
    void onUnload();
};

class FDBusEndLife : public IPlugin {
public:
    virtual void onLoad(INode *node);
    void onUnload();
};
#endif // FS_BUS_SERVLET_H
